package com.jlt.service.dic;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.jlt.dao.dic.DicEntityDao;
import com.jlt.entity.dic.DicEntity;

/**
 * 字典相关实体的管理类,.
 * 
 * @author zhoutao
 */
// Spring Bean的标识.
@Component
// 默认将类中的所有函数纳入事务管理.
@Transactional
public class DicEntityManager {

	private static Logger logger = LoggerFactory
			.getLogger(DicEntityManager.class);

	private DicEntityDao dicEntityDao;

	// -- dic entity Manager --//
	@Transactional(readOnly = true)
	public DicEntity getDicEntity(Long id) {
		return dicEntityDao.get(id);
	}

	/**
	 * 使用属性过滤条件查询字典实体.
	 */
	@Transactional(readOnly = true)
	public Page<DicEntity> searchDicEntity(final Page<DicEntity> page,
			final List<PropertyFilter> filters, final Long dicTypeId) {
		return dicEntityDao.findPage(page, filters, dicTypeId);
	}

	@Transactional(readOnly = true)
	public List<DicEntity> getAllDicEntity() {
		return dicEntityDao.getAll("id", true);
	}

	public void saveDicEntity(DicEntity entity) {
		dicEntityDao.save(entity);
	}

	public void deleteDicEntity(Long id) {
		logger.info("save dic entity success");
		dicEntityDao.delete(id);
	}
	
	public DicEntity getDicEntityByCode(String code){
		return dicEntityDao.getDicEntityByCode(code);
	}
	
	public List<DicEntity> findDicEntityByTypeCode(String dicTypeCode){
		return dicEntityDao.findDicEntityByTypeCode( dicTypeCode);
	}
	@Autowired
	public void setDicEntity(DicEntityDao dicEntityDao) {
		this.dicEntityDao = dicEntityDao;
	}
}
